package com.kun.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kun.entity.SysParam;
import com.kun.dto.SysParamDTO;
import com.kun.service.SysParamService;
import com.kun.util.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kun.li
 */
@RestController
@RequestMapping("param")
@RequiredArgsConstructor
@Tag(name = "参数管理")
public class ParamController {

    private final SysParamService sysParamService;

    @PostMapping("selectPage")
    @Operation(summary = "参数分页列表")
    public ResponseResult<Page<SysParam>> selectPage(@RequestBody SysParamDTO sysParamDTO) {
        Page<SysParam> sysParamPage = sysParamService.page(Page.of(sysParamDTO.getPage(), sysParamDTO.getSize()));
        return ResponseResult.success(sysParamPage);
    }

    @PostMapping("save")
    @Operation(summary = "参数保存")
    public ResponseResult<Boolean> saveParam(@RequestBody SysParam sysParam) {
        return ResponseResult.success(sysParamService.save(sysParam));
    }


    @PostMapping("update")
    @Operation(summary = "参数修改")
    public ResponseResult<Boolean> updateParam(@RequestBody SysParam sysParam) {
        return ResponseResult.success(sysParamService.updateById(sysParam));
    }

    @DeleteMapping("delete")
    @Operation(summary = "参数删除")
    public ResponseResult<Boolean> deleteParam(@RequestBody List<String> ids) {
        return ResponseResult.success(sysParamService.removeBatchByIds(ids));
    }


}
